

//多态发生的条件：1.向上转型 2.重写 3.继承
class Animal{
    String name;
    int age;
    public void eat(){

        System.out.println(name+" 正在吃饭");
    }

}
class Dog extends Animal{


     @Override
    public void eat() {

         System.out.println(name+" 正在吃狗粮");
    }
    public  void wangwang() {
        System.out.println(name+"汪汪叫");
    }
}
class Bird extends Animal {


      @Override
    public void eat(){

          System.out.println(name+" 正在吃鸟粮");
    }
    public void fly() {
        System.out.println(name+"正在飞");
    }
}

public class Text {
    public static void main(String[] args) {
        Animal animal=new Dog();

        //向下转型
        /*Dog dog=(Dog)animal;
        dog.name="遇见";
        dog.wangwang()*/;
        if(animal instanceof Bird) {
            Bird bird = (Bird) animal;
            bird.fly();
        }
    }
    public static void main1(String[] args) {
        Animal animal1=new Dog();
        Animal animal2=new Bird();
        animal1.name="遇见";
        animal2.name="七月";
        animal1.eat();
        animal2.eat();
    }
}
